<template>
  <VSelects v-bind="$attrs" :dataSourse="allList" />
</template>

<script setup>
import { getData, configAPI } from "./data.js";
const props = defineProps({
  url: {
    type: String, //url
    default: null,
  },
  baseURL: {
    type: String, //baseURL
    default: null,
  },
  params: {
    type: Object, //params
    default: null,
  },
  method: {
    type: String, //POST,GET
    default: "get",
  },
  configType: {
    type: String, //配置类型
    default: null,
  },
  moduleName: {
    type: String, //配置类型
    default: null,
  },
});
const allList = computed(() => {
  return options.value;
});
onMounted(() => {
  getList();
});
const options = ref([]);
async function getList() {
  options.value = [];
  try {
    if (props?.configType) {
      const data = configAPI[props.configType];
      const { baseURL, url, method, params } = data;
      const res = await getData(baseURL, url, method, params);
      options.value = res.data;
      return;
    }
    if (!props.url) return;
    const res = await getData(
      props.baseURL,
      props.url,
      props.method,
      props.params
    );
    options.value = res.data;
  } catch (error) {
    console.error("An error occurred:", error);
  }
}
</script>

<style scoped></style>
